package day01;

/**
 * @author feng
 * @Date 2021/7/8 7:17
 */

//多线程操作同一个的对象,数据紊乱，共享数据，线程不安全

public class ThreadTest04 implements Runnable {

    private int ticket=10;

    @Override
    public void run() {
        while (true){
            if(ticket<=0){
                break;
            }
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"拿到"+ticket-- +"张票");
        }

    }
    public static void main(String[] args) {
        ThreadTest04 test04 = new ThreadTest04();

        new Thread(test04,"小明").start();
        new Thread(test04,"老师").start();
        new Thread(test04,"黄牛").start();
    }


}


/* 输出结果:
*
* 老师拿到7张票
  小明拿到7张票
*
* */